package com.crrc.yzt.demo.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.crrc.yzt.demo.activity.CarHomeActivity
import com.crrc.yzt.demo.blue.databinding.FragmentPasswordLoginBinding

class PasswordLoginFragment : Fragment() {

    private var viewBinding: FragmentPasswordLoginBinding? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        viewBinding = FragmentPasswordLoginBinding.inflate(inflater, container, false)
        viewBinding?.apply {
            username = "admin"
            password = "123456"
        }
        return viewBinding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        viewBinding?.apply {
            btnLogin.setOnClickListener {

                if(viewBinding?.username?.isNotBlank() == true && viewBinding?.password?.isNotBlank() == true){
                    startActivity(Intent(activity, CarHomeActivity::class.java))
                    activity?.finish()
                }else{
                    Toast.makeText(activity,"请输入用户名或者密码",Toast.LENGTH_SHORT).show()
                    return@setOnClickListener
                }


            }
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        viewBinding = null
    }


}